/*
 * @lc app=leetcode.cn id=47 lang=golang
 *
 * [47] 全排列 II
 */

// @lc code=start
func permuteUnique(nums []int) (ans [][]int) {
	if len(nums) == 1 {
		return append(ans, nums)
	}

	sort.Ints(nums)
	for i := 0; i < len(nums); i++ {
		if i > 0 && nums[i] == nums[i-1] {
			continue
		}
		temp := make([]int, len(nums))
		copy(temp, nums)
		for _, v := range permuteUnique(append(temp[:i], temp[i+1:]...)) {
			ans = append(ans, append([]int{nums[i]}, v...))
		}
	}
	return
}

// @lc code=end

